package com.jdz.gxq.info.admin.employment.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.employment.bo.Employment;
import com.jdz.gxq.info.admin.employment.form.EditEmploymentForm;
import com.jdz.gxq.info.admin.employment.service.EmploymentService;
import com.jdz.gxq.info.common.action.CommonAction;

public class SaveEmploymentAction extends CommonAction {

	private EmploymentService employmentService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		EditEmploymentForm editEmploymentForm = (EditEmploymentForm) form;
		
		Employment employment = editEmploymentForm.getEmployment();
		
		// employment名重复验证(其他后台逻辑验证也类似处理)
		if (!employmentService.checkEmploymentName(employment, 2)) {
			ActionMessages messages = new ActionMessages();
			messages.add("employment.enterpriseName", new ActionMessage("error.employmentNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}

		employment.setModifiedBy(getUserId(request));
		
		employmentService.updateEmployment(employment);
		
		return mapping.findForward("success");
	}

	public void setEmploymentService(EmploymentService employmentService) {
		this.employmentService = employmentService;
	}
}

